setwd("~/Lehigh University Dropbox/Marie Schenk/RI_RCT_BraverAngels/Analysis/Replication_PolComm_anon_v2/")
#turn off exponential notation
options(scipen=999)
library(haven)
library(dplyr)
data <- read_dta("Data/Raw/endline_1_merged.dta")
# Define the list of dependent variables
dependent_vars <- c("aff_pol_idx_out", "aff_pol_idx",
"therm_diff", "trust_diff",
"comfort_outparty_friends", "comfort_outparty_neighbors",
"comfort_outparty_marriage", "threat_outparty_cit", "threat_outparty_pol",
"any_social", "donate_total_any",
"donate_allsides_any", "donate_lrc_any", "donate_ba_any", "answered_amtalks")
# Create an empty data frame to store results
results <- data.frame(variable = character(), mean = numeric(), sd = numeric(), stringsAsFactors = FALSE)
# Loop through each variable to calculate mean and standard deviation
for (var in dependent_vars) {
stats <- data %>%
summarise(mean = mean(!!sym(var), na.rm = TRUE),
sd = sd(!!sym(var), na.rm = TRUE))
results <- rbind(results, data.frame(variable = var, mean = stats$mean, sd = stats$sd, stringsAsFactors = FALSE))
}
# Define the list of dependent variables
dependent_vars <- c("aff_pol_idx_out", "aff_pol_idx",
"therm_diff", "trust_diff",
"comfort_outparty_friends", "comfort_outparty_neighbors",
"comfort_outparty_marriage", "threat_outparty_cit", "threat_outparty_pol",
"any_social", "donate_total_any",
"donate_allsides_any", "donate_lrc_any", "donate_ba_any", "answered_amtalks")
# Create an empty data frame to store results
results <- data.frame(variable = character(), mean = numeric(), sd = numeric(), stringsAsFactors = FALSE)
# Loop through each variable to calculate mean and standard deviation
for (var in dependent_vars) {
stats <- data %>%
summarise(mean = mean(!!sym(var), na.rm = TRUE),
sd = sd(!!sym(var), na.rm = TRUE))
results <- rbind(results, data.frame(variable = var, mean = stats$mean, sd = stats$sd, stringsAsFactors = FALSE))
}
colnames(data)
#marie's
setwd("~/Lehigh University Dropbox/Marie Schenk/RI_RCT_BraverAngels/Analysis/Analysis_Study2/Data/Cleaned")
##
## import data ##
##
data <- read_dta("endline_1_merged.dta")
colnames(data)
setwd("~/Lehigh University Dropbox/Marie Schenk/RI_RCT_BraverAngels/Analysis/Replication_PolComm_anon_v2/")
#turn off exponential notation
options(scipen=999)
library(haven)
library(dplyr)
data <- read_dta("Data/Cleaned/endline_1_merged.dta")
# Define the list of dependent variables
dependent_vars <- c("aff_pol_idx_out", "aff_pol_idx",
"therm_diff", "trust_diff",
"comfort_outparty_friends", "comfort_outparty_neighbors",
"comfort_outparty_marriage", "threat_outparty_cit", "threat_outparty_pol",
"any_social", "donate_total_any",
"donate_allsides_any", "donate_lrc_any", "donate_ba_any", "answered_amtalks")
# Create an empty data frame to store results
results <- data.frame(variable = character(), mean = numeric(), sd = numeric(), stringsAsFactors = FALSE)
# Loop through each variable to calculate mean and standard deviation
for (var in dependent_vars) {
stats <- data %>%
summarise(mean = mean(!!sym(var), na.rm = TRUE),
sd = sd(!!sym(var), na.rm = TRUE))
results <- rbind(results, data.frame(variable = var, mean = stats$mean, sd = stats$sd, stringsAsFactors = FALSE))
}
# Format the results to three decimal places
results_rounded <- results %>%
mutate(mean = round(mean, 3), sd = round(sd, 3))
colnames(data)
# Print the results as a LaTeX table
kable(results_rounded, format = "latex", booktabs = TRUE, escape = FALSE, caption = "Summary Statistics for Dependent Variables")
library(knitr)
# Print the results as a LaTeX table
kable(results_rounded, format = "latex", booktabs = TRUE, escape = FALSE, caption = "Summary Statistics for Dependent Variables")
